<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form action="" method="post">
		<table border="1" cellspacing="0" cellpadding="10px" id="stuTable">
			<tr>
				<th></th>				
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>家庭住址</th>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">女</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">女</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
		</table>
		</form>
		<input type="checkbox" name="" id="checkAllId" value="" onclick="doSelAll();"/>全选
		<input type="checkbox" name="" id="checkAllId1" value="" onclick="doSelAll1();"/>全选女
		<input type="checkbox" name="" id="checkAllId2" value="" onclick="doSelAll2();"/>全选男
	</body>
	<script type="text/javascript">
		function doSelAll(){
			var stuTableObj = document.getElementById('stuTable');
			var inputAll = stuTableObj.getElementsByTagName('input');
			var checkAllValue = document.getElementById('checkAllId').checked;
			for(var i=0;i<inputAll.length;i++){
				inputAll[i].checked = checkAllValue;
			}
			
			
		}
		
		function doSelAll1(){
			var all_sex=document.getElementsByClassName('sex');
						for (var i = 0; i < all_sex.length; i++) {
							if (all_sex[i].innerText=='女') {
								var stuTableObj= document.getElementById('stuTable');
								var inputAll= stuTableObj.getElementsByTagName('input');
								var checkAllValue=document.getElementById('checkAllId1').checked;
								inputAll[i].checked=checkAllValue;
							} 
						}
			
			
		}
		function doSelAll2(){
			var all_sex=document.getElementsByClassName('sex');
						for (var i = 0; i < all_sex.length; i++) {
							if (all_sex[i].innerText=='男') {
								var stuTableObj= document.getElementById('stuTable');
								var inputAll= stuTableObj.getElementsByTagName('input');
								var checkAllValue=document.getElementById('checkAllId2').checked;
								inputAll[i].checked=checkAllValue;
							} 
						}
			
			
		}
	</script>
</html>
